{include file="public/header"}
<!-- 表单 -->
<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .layui-form-item {
        margin-right: 30%;
    }

    .layui-show {
        padding-left: 50px;
    }
</style>
</head>

<body>
    <div class="cBody">
        <form class="layui-form">
            <div class="layui-collapse">
                {volist name="controller" id="v"}
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">
                        <input type="checkbox" name="{$v.controller}" title="{$v.title}" lay-skin="primary"
                            lay-filter="parent_controller" class="parent_controller">
                    </h2>
                    <div class="layui-colla-content layui-show">
                        {foreach $actions as $k1=>$v1}
                        {if $v['controller']==$k1}
                        {volist name="$v1" id="v2"}
                        <input type="checkbox" name="ability[]" title="{$v2.title}" lay-skin="primary"
                            lay-filter="sublevel" value="{$v.controller}@{$v2.actions}" class="{$v.controller}" {if in_array($v["controller"].'@'.$v2["actions"],$ability)}checked{/if}>
                        {/volist}
                        {/if}
                        {/foreach}
                    </div>
                </div>
                {/volist}
            </div>
            <div class="layui-input-block" style="margin-top: 20px;">
                <button class="layui-btn" lay-submit lay-filter="submitBut">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
        <script>
            //表单提交
            layui.use(['form', 'layer'], function () {
                var form = layui.form;
                var layer = layui.layer;
                form.render();
                form.on('checkbox(parent_controller)', function (data) {
                    // console.log(data.elem.name); //得到checkbox原始DOM对象
                    // console.log(data.elem.checked); //是否被选中，true或者false
                    if (data.elem.checked === true) {
                        $('.' + data.elem.name).prop("checked", true); form.render();
                    } else {
                        $('.' + data.elem.name).prop("checked", false); form.render();
                    }
                });
                form.on('checkbox(sublevel)', function (data) {
                    var name = $(this).attr('class');
                    if (data.elem.checked === true) {
                        $('input[name="' + name + '"]').prop("checked", true); form.render();
                    } else {
                        var number = 0;
                        $('.' + name).each(function () {
                            if ($(this).is(':checked')) {
                                number = number + 1;
                            }
                        });
                        if (number == 0) {
                            $('input[name="' + name + '"]').prop("checked", false); form.render();
                        }
                    }
                });
                //监听提交
                form.on('submit(submitBut)', function (data) {
                    // console.log(data.field);return false;
                    ajax_submit(data.field, '', 'demo');
                    return false;
                });
            });
        </script>
    </div>
</body>
{include file="public/footer"}